<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\listing;
use App\Newsinfo;
use Illuminate\Http\Request;

class newController extends Controller
{
  //  use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
//首页客户端的列表
	public function show(){
		$list = DB::select('select * from class ;');
		$newsinfo = DB::select('select * from newsinfo');
		/*var_dump($newsinfo);*/
		return view('index',['newsinfo' =>$newsinfo],['list' =>$list]);
	}


	public function view($id){
		/*var_dump($newsinfo);*//*
		$class = DB::table('class')->where('id', )->get();*/
		/* var_dump($view);*/
		$view = DB::table('newsinfo')->where('id', $id)->get();
		return view('view', ['view' =>$view]);
	}

	public function list($id){
		$viewlist = DB::table('class')
		->leftJoin('newsinfo', 'class.id', '=', 'newsinfo.classid')->where('classid', $id)
		->get();
		return view('list', ['list' =>$viewlist]);
	}



	public function news_info(){
		$list = DB::select('select * from class ;');
		$newsinfo = DB::select('select * from newsinfo');
		return view('indexsystem', ['newsinfo' => $newsinfo,'list' => $list]);
	}


//添加新闻
	public function addnew(Request $request){
    /* $Newsin = Newsinfo::all();
    dd($Newsin);*/
    /* dd($request);*/
    $addnew = new Newsinfo;
    $addnew->title = $request->title;
    $addnew->time = $request->time;
    $addnew->writer = $request->writer;
    $addnew->classid = $request->class;
    $addnew->content = $request->content;
    $addnew->save();
    return redirect('/indexsystem');
}

//修改新闻
public function modify(Request $request){
	$addnew = new Newsinfo;
	$id=$request->id;
	$title = $request->title;
	$writer=$request->writer;
	$content=$request->content;
	$time= $request->time;
	Newsinfo::where('id',$id)
	->update(['title' => $title,'writer' => $writer,'content' => $content,'time' => $time]);
	/* dd($request);*/
	return redirect('/indexsystem');

}

//删除新闻
public function delete($id){
	$delete = new Newsinfo;
	$flight =Newsinfo::find($id);
	$flight->delete();
	return redirect('/indexsystem');
}



//展示栏目

public function listshow(){
	$list = DB::select('select * from class ;');
	return view('indexsystemlist', ['list' => $list]);
}	






//添加栏目
public function addnewlist(Request $request){
    /* $Newsin = Newsinfo::all();
    dd($Newsin);*/
    /* dd($request);*/
    $addnew = new listing;
    $addnew->classname = $request->title;
    $addnew->save();
    return redirect('/indexsystemlist');
}




//修改list
public function modifylist(Request $request){
	$addnew = new listing;
	$id=$request->id;
	$title = $request->title;
	listing::where('id',$id)
	->update(['classname' => $title]);
	return redirect('/indexsystemlist');

}


//list删除
public function deletelist($id){
	$delete = new listing;
	$flight =listing::find($id);
	$flight->delete();
	return redirect('/indexsystemlist');
}



}

